﻿using Interfaces.Model;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace Models
{
    public class tb_WorkPieceDataCapture_Request
    {
        public int? iID { get; set; } // 自增ID
        public string? ZC_SerialNo { get; set; } // 总成设备标识码
        public string? ZC_Model { get; set; } // 总成型号
        public string? ZC_Time { get; set; } // 总成生产时间
        public string? ZC_LaserNo { get; set; } // 总成激光打码编码
        public bool? CheckLaserNo { get; set; } // 是否校验激光打码重复
        public string? ZC_ProduceMode { get; set; } // 生产模式
        public string? ZC_Result { get; set; } // 总成综合结果
        public string? FLJ_ZT_Model { get; set; } // 分零件：主体型号码
        public string? FLJ_ZT_Material { get; set; } // 分零件：主体物料编码
        public string? FLJ_YCQ_Model { get; set; } // 分零件：一次圈型号码
        public string? FLJ_YCQ_Material { get; set; } // 分零件：一次圈物料编码
        public string? FLJ_YCQ_Result { get; set; } // 分零件：一次圈检测结果
        public string? FLJ_YCQ_Photo { get; set; }  //分零件：一次圈相机存储路径
        public string? FLJ_GLH_Model { get; set; } // 分零件：隔离环型号码
        public string? FLJ_GLH_Material { get; set; } // 分零件：隔离环物料编码
        public string? FLJ_GLH_Result { get; set; } // 分零件：隔离环检测结果
        public string? FLJ_GLH_Photo { get; set; }  //分零件：隔离环相机存储路径
        public string? FLJ_ECQ_Model { get; set; } // 分零件：二次圈型号码
        public string? FLJ_ECQ_Material { get; set; } // 分零件：二次圈物料编码
        public string? FLJ_ECQ_Result { get; set; } // 分零件：二次圈检测结果
        public string? FLJ_ECQ_Photo { get; set; }  //分零件：二次圈相机存储路径
        public string? FLJ_KZH_Model { get; set; } // 分零件：安全环型号码
        public string? FLJ_KZH_Material { get; set; } // 分零件：安全环物料编码
        public string? FLJ_KZH_Result { get; set; } // 分零件：安全环检测结果
        public double? FLJ_KZH_Value { get; set; } // 分零件：安全环检测位移偏差
        public double? FLJ_KZH_Upper { get; set; } // 分零件：安全环位移检测参数上限
        public double? FLJ_KZH_Lower { get; set; } // 分零件：安全环位移检测参数下限
        public string? FLJ_KZH_PressureResult { get; set; } // 分零件：安全环压力检测结果
        public string? FLJ_WM_Model { get; set; } // 分零件：外密型号码
        public string? FLJ_WM_Material { get; set; } // 分零件：外密物料编码
        public string? FLJ_WM_Result { get; set; } // 分零件：外密检测结果
        public string? FLJ_WM_Photo1 { get; set; } // 分零件：外密相机1存储路径
        public string? FLJ_WM_Photo2 { get; set; } // 分零件：外密相机2存储路径
        public string? FLJ_SK_Model { get; set; } // 分零件：锁扣型号码
        public string? FLJ_SK_Material { get; set; } // 分零件：锁扣物料编码
        public string? FLJ_SK_Result { get; set; } // 分零件：锁扣检测结果
        public string? FLJ_SK_Photo { get; set; } // 分零件：锁扣相机存储路径
        public string? JCY_QM_Result { get; set; } // 检测仪：气密检测结果
        public int? JCY_QM_Program { get; set; } // 检测仪：气密检测程序号
        public double? JCY_QM_Pressure { get; set; } // 检测仪：气密检测压力值
        public string? JCY_QM_PressureUnit { get; set; } // 检测仪：内密气密压力单位
        public double? JCY_QM_Leak { get; set; } // 检测仪：气密检测泄漏值
        public string? JCY_QM_LeakUnit { get; set; } // 检测仪：内密气密泄漏单位
        public string? JCY_KTQM_Result { get; set; } // 检测仪：壳体气密检测结果
        public int? JCY_KTQM_Program { get; set; } // 检测仪：壳体气密程序号
        public double? JCY_KTQM_Pressure { get; set; } // 检测仪：壳体气密压力值
        public string? JCY_KTQM_PressureUnit { get; set; } // 检测仪：壳体气密压力单位
        public double? JCY_KTQM_Leak { get; set; } // 检测仪：壳体气密泄漏值
        public string? JCY_KTQM_LeakUnit { get; set; } // 检测仪：壳体气密泄漏单位
        public string? FLJ_SL_Photo { get; set; }   //分零件：上料相机路径
        public string? FLJ_SL_Photo2 { get; set; }   //分零件：上料相机路径2
        public string? FLJ_NM_Photo { get; set; }   //分零件：内密相机存储路径
        public string? FLJ_NM_Result { get; set; }  //分零件：内密检测结果

        // 打码检测新增字段
        public string? ZC_DM_Result { get; set; }   // 打码检测结果（OK/NG/NA）
        public string? ZC_DM_ScanText { get; set; } // 打码扫码字符
        public string? ZC_DM_Photo { get; set; }    // 打码检测存储路径

        public string? LoginUser { get; set; }      //登录人员
        public DateTime? dDate { get; set; } //保存时间

        public int CoordinateCount { get; set; }    //取坐标的数据集合的数量
        public List<CoordinatePoint>? CoordinateData { get; set; }  //坐标数据的JSON字符串
        public static tb_WorkPieceDataCapture_Realtime ToDomainModel(tb_WorkPieceDataCapture_Request request)
        {
            if (request.CoordinateData != null && request.CoordinateCount > 0)  //根据数量接收坐标数据
                request.CoordinateData = request.CoordinateData.Take(request.CoordinateCount).ToList();
            return new tb_WorkPieceDataCapture_Realtime()
            {
                iID = request.iID, // 自增ID
                ZC_SerialNo = request.ZC_SerialNo, // 总成设备标识码
                ZC_Model = request.ZC_Model, // 总成型号
                ZC_Time = request.ZC_Time, // 总成生产时间
                ZC_LaserNo = request.ZC_LaserNo, // 总成激光打码编码
                CheckLaserNo = request.CheckLaserNo, // 是否校验激光打码重复
                ZC_ProduceMode = request.ZC_ProduceMode, // 生产模式
                ZC_Result = request.ZC_Result, // 总成综合结果
                FLJ_ZT_Model = request.FLJ_ZT_Model, // 分零件：主体型号码
                FLJ_ZT_Material = request.FLJ_ZT_Material, // 分零件：主体物料编码
                FLJ_YCQ_Model = request.FLJ_YCQ_Model, // 分零件：一次圈型号码
                FLJ_YCQ_Material = request.FLJ_YCQ_Material, // 分零件：一次圈物料编码
                FLJ_YCQ_Result = request.FLJ_YCQ_Result, // 分零件：一次圈检测结果
                FLJ_YCQ_Photo = request.FLJ_YCQ_Photo,  //分零件：一次圈相机存储路径
                FLJ_GLH_Model = request.FLJ_GLH_Model, // 分零件：隔离环型号码
                FLJ_GLH_Material = request.FLJ_GLH_Material, // 分零件：隔离环物料编码
                FLJ_GLH_Result = request.FLJ_GLH_Result, // 分零件：隔离环检测结果
                FLJ_GLH_Photo = request.FLJ_GLH_Photo,  //分零件：隔离环相机存储路径
                FLJ_ECQ_Model = request.FLJ_ECQ_Model, // 分零件：二次圈型号码
                FLJ_ECQ_Material = request.FLJ_ECQ_Material, // 分零件：二次圈物料编码
                FLJ_ECQ_Result = request.FLJ_ECQ_Result, // 分零件：二次圈检测结果
                FLJ_ECQ_Photo = request.FLJ_ECQ_Photo,  //分零件：二次圈相机存储路径
                FLJ_KZH_Model = request.FLJ_KZH_Model, // 分零件：安全环型号码
                FLJ_KZH_Material = request.FLJ_KZH_Material, // 分零件：安全环物料编码
                FLJ_KZH_Result = request.FLJ_KZH_Result, // 分零件：安全环检测结果
                FLJ_KZH_Value = request.FLJ_KZH_Value, // 分零件：安全环检测位移偏差
                FLJ_KZH_Upper = request.FLJ_KZH_Upper, // 分零件：安全环位移检测参数上限
                FLJ_KZH_Lower = request.FLJ_KZH_Lower, // 分零件：安全环位移检测参数下限
                FLJ_KZH_PressureResult = request.FLJ_KZH_PressureResult, // 分零件：安全环压力检测结果
                FLJ_WM_Model = request.FLJ_WM_Model, // 分零件：外密型号码
                FLJ_WM_Material = request.FLJ_WM_Material, // 分零件：外密物料编码
                FLJ_WM_Result = request.FLJ_WM_Result, // 分零件：外密检测结果
                FLJ_WM_Photo1 = request.FLJ_WM_Photo1, // 分零件：外密相机1存储路径
                FLJ_WM_Photo2 = request.FLJ_WM_Photo2, // 分零件：外密相机2存储路径
                FLJ_SK_Model = request.FLJ_SK_Model, // 分零件：锁扣型号码
                FLJ_SK_Material = request.FLJ_SK_Material, // 分零件：锁扣物料编码
                FLJ_SK_Result = request.FLJ_SK_Result, // 分零件：锁扣检测结果
                FLJ_SK_Photo = request.FLJ_SK_Photo, // 分零件：锁扣相机存储路径
                JCY_QM_Result = request.JCY_QM_Result, // 检测仪：气密检测结果
                JCY_QM_Program = request.JCY_QM_Program, // 检测仪：气密检测程序号
                JCY_QM_Pressure = request.JCY_QM_Pressure, // 检测仪：气密检测压力值
                JCY_QM_PressureUnit = request.JCY_QM_PressureUnit, // 检测仪：内密气密压力单位
                JCY_QM_Leak = request.JCY_QM_Leak, // 检测仪：气密检测泄漏值
                JCY_QM_LeakUnit = request.JCY_QM_LeakUnit, // 检测仪：内密气密泄漏单位
                JCY_KTQM_Result = request.JCY_KTQM_Result, // 检测仪：壳体气密检测结果
                JCY_KTQM_Program = request.JCY_KTQM_Program, // 检测仪：壳体气密程序号
                JCY_KTQM_Pressure = request.JCY_KTQM_Pressure, // 检测仪：壳体气密压力值
                JCY_KTQM_PressureUnit = request.JCY_KTQM_PressureUnit, // 检测仪：壳体气密压力单位
                JCY_KTQM_Leak = request.JCY_KTQM_Leak, // 检测仪：壳体气密泄漏值
                JCY_KTQM_LeakUnit = request.JCY_KTQM_LeakUnit, // 检测仪：壳体气密泄漏单位
                FLJ_SL_Photo = request.FLJ_SL_Photo,   //分零件：上料相机路径
                FLJ_SL_Photo2 = request.FLJ_SL_Photo2,   //分零件：上料相机路径2
                FLJ_NM_Photo = request.FLJ_NM_Photo,   //分零件：内密相机存储路径
                FLJ_NM_Result = request.FLJ_NM_Result,  //分零件：内密检测结果
                ZC_DM_Result = request.ZC_DM_Result,   // 打码检测结果（OK/NG/NA）
                ZC_DM_ScanText = request.ZC_DM_ScanText, // 打码扫码字符
                ZC_DM_Photo = request.ZC_DM_Photo,    // 打码检测存储路径
                LoginUser = request.LoginUser,      //登录人员
                dDate = request.dDate, //保存时间
                CoordinateData = JsonConvert.SerializeObject(request.CoordinateData)
            };
        }
    }
}
